home *** CD-ROM | disk | FTP | other *** search
- Path: theory.lcs.mit.edu!wald
- From: wald@theory.lcs.mit.edu (David Wald)
- Newsgroups: comp.lang.c++
- Subject: Re: extending c++ to include type bool
- Date: 19 Apr 1996 13:46:44 GMT
- Organization: Theory of Computation, LCS, MIT
- Message-ID: <WALD.96Apr19094644@woodpecker.lcs.mit.edu>
- References: <bdsilver.829698454@extro> <3176C470.2647@cs.tu-berlin.de>
- NNTP-Posting-Host: woodpecker.lcs.mit.edu
- In-reply-to: Roman Lechtchinsky's message of Fri, 19 Apr 1996 00:38:40 +0200
-
- In article <3176C470.2647@cs.tu-berlin.de> Roman Lechtchinsky
- <wolfro@cs.tu-berlin.de> writes:
- >Brett David Silverman wrote:
- >> The question: Is it possible to create a class bool, in such a way
- >> that it looks, smells, feels, talks, etc like the "real" bool? To
- >> the extent that I can create this class so that I am guaranteed
- >> that the source will work, even though I can't see the source?
-
- >I think one of the following should do ( depending on the compiler ):
- >enum bool { false, true };
- >or
- >enum { false, true };
- >typedef int bool;
-
- (Didn't we just go through this?) Thanks to overloading, it's not
- possible for a user-defined type to completely emulate the C++ bool.
- If you need a guarantee that some arbitrary code written with the C++
- bool type will work with your user-defined type, you're out of luck.
-
- Consider:
-
- int f(bool);
- int f(int);
- int g(int a, int b) { return f(a == b); }
-
- In a system without built-in bool, no user-defined bool will result in
- a call to f(bool). You can't change the type of a built-in comparison
- operator.
-
- -David
- --
- ============================================================================
- David Wald http://theory.lcs.mit.edu/~wald/ wald@theory.lcs.mit.edu
- ============================================================================
-